package bank
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import utils.DisplayTool;
	import utils.EnterFrameTimer;
	
	public class ChestHint extends Sprite
	{
		private var dWidth:int = 150;
		private var dHeight:int = 38;
		private var elp:int = 10;
		
		private var text:TextField;
		private var timer:EnterFrameTimer;
		private var bg:Shape;
		
		public function ChestHint()
		{
			initText();
			drawArrow();
			initTimer();
			this.mouseEnabled = false;
			this.mouseChildren = false;
		}
		
		private function initTimer():void
		{
			timer = new EnterFrameTimer(40,4);
			timer.addEventListener(TimerEvent.TIMER,onTimer);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE,onComplete);
		}
		
		private function onComplete(event:TimerEvent):void
		{
			timer.reset();
			addChild(text);
			this.scaleX = this.scaleY = 1;
		}
		
		private function onTimer(event:TimerEvent):void
		{
			this.scaleX = this.scaleY = .25 * (timer.currentCount + 1);	
		}
		
		public function update(content:String):void
		{
			DisplayTool.removeChild(text.parent,text);
			this.scaleX = this.scaleY = 0.1;
			text.text = content;
			timer.start();
		}
		
		public function updateOnlyText(content:String):void
		{
			text.text = content;
		}
		
		private function initText():void
		{
			bg = new Shape();
			addChild(bg);
			bg.x = -dWidth;
			bg.y = -dHeight - 20;
			
			text = new TextField();
			text.width = dWidth + 12;
			text.height = dHeight + 12;
			text.multiline = true;
			text.wordWrap = true;
			text.x = -dWidth + 2;
			text.y = -dHeight - 20 + 2;
			
			//text.border = true;
			
			var tf:TextFormat = new TextFormat();
			tf.size = 12;
			tf.color = 0;
			tf.align = TextFormatAlign.JUSTIFY;
			text.defaultTextFormat = tf;
			addChild(text);
			
		}
		
		private function drawArrow():void
		{
			
			
			
			with(this.bg.graphics)
			{
				clear();
				lineStyle(2,0xFFFFFF);
				beginFill(0xFFFFFF,.8);
				
				moveTo(elp,0);
				lineTo(this.width - elp,0);
				curveTo(this.width,0,this.width,elp);
				lineTo(this.width,text.height - elp);
				curveTo(this.width,text.height,this.width - elp,text.height);
				lineTo(this.width * .8,text.height);
				lineTo(this.width * .8 , text.height + 20);
				lineTo(this.width * .6, text.height);
				lineTo(elp,text.height);
				curveTo(0,text.height,0,text.height - elp);
				lineTo(0,elp);
				curveTo(0,0,elp,0);
				endFill();
			}
		}
		
		/*private function drawBg():void
		{
			with(this.graphics)
			{
				clear();
				lineStyle(1,0xCCCCCC);
				beginFill(0xEEEEEE,.5);
				moveTo(
			}
		}*/
	}
}